package com.clkj.zhonghui.dao.points;

import com.clkj.zhonghui.pojo.points.RebatePoints;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @Author 周佳润
 * @Date 2024/9/4 上午9:45
 */
@Repository
public interface RebatePointsMapper extends Mapper<RebatePoints> {
    @Select("SELECT a.* ,b.user_name  FROM t_zh_rebatePoints a LEFT JOIN t_zh_user b ON a.user_id = b.user_id WHERE a.user_id = #{userId} ORDER BY point_id DESC")
    List<RebatePoints> listPoints(Integer userId);

    @Select("SELECT " +
            " t.*," +
            " u1.user_name AS userName," +
            " u2.user_name AS sourceName," +
            " u3.user_name AS exportName " +
            " FROM" +
            " t_zh_rebatePoints AS t" +
            " LEFT JOIN t_zh_user AS u1 ON t.user_id = u1.user_id" +
            " LEFT JOIN t_zh_user AS u2 ON t.source = u2.user_id" +
            " LEFT JOIN t_zh_user AS u3 ON t.export_id = u3.user_id" +
            " WHERE" +
            " t.user_id= #{userId}")
    List<RebatePoints> listPointsFinal(Integer userId);

    @Select("SELECT t.*," +
            "u1.user_name AS userName, " +
            "u2.user_name AS sourceName," +
            "u3.user_name AS exportName " +
            " FROM t_zh_rebatePoints AS t " +
            " LEFT JOIN t_zh_user AS u1 ON t.user_id = u1.user_id" +
            " LEFT JOIN t_zh_user AS u2 ON t.source = u2.user_id" +
            " LEFT JOIN t_zh_user AS u3 ON t.export_id = u3.user_id " +
            " WHERE t.user_id = #{userId} AND point_type IN (1, 3) AND expiry_date > GETDATE() ORDER BY expiry_date ASC")
    List<RebatePoints> notExpired(Integer userId);

    @Select("SELECT t.*," +
            "u1.user_name AS userName, " +
            "u2.user_name AS sourceName," +
            "u3.user_name AS exportName " +
            " FROM t_zh_rebatePoints AS t " +
            " LEFT JOIN t_zh_user AS u1 ON t.user_id = u1.user_id" +
            " LEFT JOIN t_zh_user AS u2 ON t.source = u2.user_id" +
            " LEFT JOIN t_zh_user AS u3 ON t.export_id = u3.user_id " +
            " WHERE t.user_id = #{userId} AND point_type IN (1, 3) AND expiry_date <= GETDATE() ORDER BY expiry_date ASC")
    List<RebatePoints> isExpired(Integer userId);

    @Select("SELECT t.*," +
            "u1.user_name AS userName, " +
            "u2.user_name AS sourceName," +
            "u3.user_name AS exportName " +
            " FROM t_zh_rebatePoints AS t " +
            " LEFT JOIN t_zh_user AS u1 ON t.user_id = u1.user_id" +
            " LEFT JOIN t_zh_user AS u2 ON t.source = u2.user_id" +
            " LEFT JOIN t_zh_user AS u3 ON t.export_id = u3.user_id " +
            " WHERE t.user_id = #{userId} AND point_type IN (0, 2)")
    List<RebatePoints> transferOut(Integer userId);
}
